<?php
// This file contains two version: magento based and our own database based

// -------------------magento based version start-----------------------
if ($_SESSION['m'] == 1) {
// show the categories for example fast food and grocery
for ($i = 0; $i < $len_category; $i++) {
echo <<< HERE
				<section>
					<article>
						<header class="button-header">
HERE;
$catid = $children[$i]['category_id'];
$cat = $soap->call ($session_id, 'catalog_category.info', $catid);
// echo print_r($cat);
// echo $cat['image'];
echo 						"<a href=\"#\" class=\"blog-title\"><img width=\"30\" height=\"25\" src=\"/magento/skin/frontend/default/default/images/" . $cat['image'] . "\"/>" . " " . 
							$children[$i]['name']."</a>";
echo <<< HERE
						</header>
						<div class="teaser row">
HERE;
// show products under each category
	$products = $soap->call( $session_id, 'catalog_category.assignedProducts', $children[$i]['category_id']);
	$len_product = sizeof($products);
	for ($j = 0; $j < $len_product; $j++) {
		$p = $soap->call ($session_id, 'catalog_product.info', $products[$j]['product_id']);
		$pid = $p['product_id'];
echo 						"&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"product.php?pid=$pid\">".$p['name']."</a><br/>";
	}
echo <<< HERE
						</div>
					</article>
				</section>
HERE;
// -----------------------magento based version end------------------------
}
} else {
// -----------------------our own database based start----------------------------
include 'ecstore_v1_config.php';
include ($site_root . '/insp-modules/misc/config.php'); 

$conn = mysql_connect($host, $user, $password) or die(mysql_error());
mysql_select_db("ecstore_nm_db");

$sql_cat = "SELECT * FROM category";
$result_cat = mysql_query($sql_cat, $conn) or die(mysql_error());

while ($row_cat = mysql_fetch_assoc($result_cat)) {
	$cat_id = $row_cat['CatID'];
	$cat_name = $row_cat['CatName'];
	echo "<section>";
	echo 	"<article>";
	echo 		"<header class='button-header'><a href='#' class='blog-title'>$cat_name</a></header>";
	echo 		"<div class='teaser row'>";
	
	$sql_prod = "SELECT * FROM product WHERE CatID='$cat_id'";
	$result_prod = mysql_query($sql_prod, $conn) or die(mysql_error());

	while ($row_prod = mysql_fetch_assoc($result_prod)) {
		$prod_id = $row_prod['ProdID'];
		$prod_name = $row_prod['Name'];
		echo		"&nbsp;&nbsp;&nbsp;&nbsp;<a href='product.php?pid=$prod_id'>$prod_name</a><br />";
	}
	echo		"</div>";
	echo	"</article>";
	echo "</section>";
}
}
// --------------------------our own database based end------------------------
?>